{% extends 'temp/index.html' %}
{% load kingadmin_tags %}

{% block  right-content-container %}
<h1>{{ model_name }}</h1>
    {% handle_readonly admin_class filed_id %}
<form method="POST" onsubmit="selectd()" class="form-horizontal">

       {% for filed in form_obj %}
            <div class="form-group">
                 <label class="col-sm-2 control-label">{{ filed.label }}</label>

                        {% if filed.name in admin_class.filter_horizontal %}
                            <div class="col-sm-10">
                            <div class="form-group">

                                <div class="col-sm-10">
                                        <div class="col-sm-5">
                                            <select multiple id="id_{{ filed.name }}_from" class="form-control">
                                                {%  get_all_data filed.name admin_class form_obj as  all_data %}
                                                 {% for obj in all_data %}
                                                     <option ondblclick=choices_select_data(this,id_{{ filed.name }}_to) value={{ obj.id }}  >{{ obj.name }}</option>
                                                  {% endfor %}
                                            </select>
                                        </div >
                                        <div  class="col-sm-5">
                                            <select tag = 1 name="{{ filed.name }}" multiple id="id_{{ filed.name }}_to" class="form-control">
                                                {%  get_choices_data filed.name admin_class form_obj as  choices_data %}
                                                 {% for obj in choices_data %}
                                                     <option ondblclick=choices_select_data(this,id_{{ filed.name }}_from) value={{ obj.id }} >{{ obj.name }}</option>
                                                  {% endfor %}
                                            </select>
                                        </div>
                                </div>
                            </div>
                            </div>

        {% else %}
         <div class="col-sm-10">

            {{ filed }}

         </div>

        {% endif %}

    {% endfor %}





</div>


</div>

    <p class="col-sm-offset-10"><input type="submit"  class="btn btn-warning"></p>

</form>


<script>
function choices_select_data(ths,dest){
    var dest_id=$(ths).parent().attr('id');
    var elm='<option '+'value = '+$(ths).val()+ ' ondblclick=choices_select_data(this,'+dest_id+')'+' >'+$(ths).text()+' </option>';
    $(dest).append(elm);
    $(ths).remove();
}
function selectd(){
    $("select[tag] option").prop('selected','true')
}
</script>
{% endblock %}

